package com.sunwayworld.basemodule.rm.train.question.resource.impl;

import java.util.ArrayList;

import com.sunwayworld.basemodule.rm.train.question.bean.LimsCoreQuestionBean;
import com.sunwayworld.basemodule.rm.train.question.bean.LimsCoreQuestionOptBean;
import com.sunwayworld.basemodule.rm.train.question.resource.LimsCoreQuestionResource;
import com.sunwayworld.basemodule.rm.train.question.service.LimsCoreQuestionOptService;
import com.sunwayworld.basemodule.rm.train.question.service.LimsCoreQuestionService;
import com.sunwayworld.basemodule.rm.train.question.validator.LimsCoreQuestionActivatableValidator;
import com.sunwayworld.basemodule.rm.train.question.validator.LimsCoreQuestionDeactivatableValidator;
import com.sunwayworld.basemodule.rm.train.question.validator.LimsCoreQuestionLastSuspendedValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.sunwayworld.framework.data.page.Pagination;
import com.sunwayworld.framework.log.annotation.Log;
import com.sunwayworld.framework.log.annotation.LogModule;
import com.sunwayworld.framework.log.annotation.LogType;
import com.sunwayworld.framework.mybatis.mapper.MatchPattern;
import com.sunwayworld.framework.mybatis.mapper.SearchFilter;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import com.sunwayworld.framework.support.activatable.resource.AbstractGenericActivatableResource;
import com.sunwayworld.framework.support.base.resource.AbstractGenericResource;
import com.sunwayworld.framework.support.suspendable.resource.AbstractGenericSuspendableResource;
import com.sunwayworld.framework.validator.data.annotation.ValidateDataWith;

@LogModule("题库管理")
@RestController
@GikamBean
public class LimsCoreQuestionResourceImpl implements LimsCoreQuestionResource,
                                                 AbstractGenericResource<LimsCoreQuestionService, LimsCoreQuestionBean, Long>,
                                                 AbstractGenericActivatableResource<LimsCoreQuestionService, LimsCoreQuestionBean, Long>,
                                                 AbstractGenericSuspendableResource<LimsCoreQuestionService, LimsCoreQuestionBean, Long> {

    @Autowired
    private LimsCoreQuestionService limsCoreQuestionService;
    
    @Autowired
    private LimsCoreQuestionOptService limsCoreQuestionOptService;

    @Override
    public LimsCoreQuestionService getService() {
        return limsCoreQuestionService;
    }

    @Override
    @Log(value = "新增题目选项", type = LogType.INSERT)
    public void insertOpt(Long id, RestJsonWrapperBean wrapper) {
        limsCoreQuestionOptService.insert(wrapper);
    }

    @Override
    @Log(value = "删除题目选项", type = LogType.DELETE)
    public void deleteOpt(RestJsonWrapperBean wrapper) {
        limsCoreQuestionOptService.delete(wrapper);
    }

    @Override
    @Log(value = "根据题目查询题目选项", type = LogType.SELECT)
    public Pagination<LimsCoreQuestionOptBean> selectQuestionOptPaginationByQuestionId(Long id, RestJsonWrapperBean wrapper) {
        return (Pagination<LimsCoreQuestionOptBean>) limsCoreQuestionOptService.selectPaginationByFilter(SearchFilter.instance().match("QUESTIONID", id).filter(MatchPattern.EQ), wrapper);
    }

    @Override
    @Log(value = "复制题目", type = LogType.INSERT)
    public ArrayList<Long> clone(RestJsonWrapperBean wrapper) {
        return (ArrayList<Long>) limsCoreQuestionService.clone(wrapper);
    }
    
    @Override
    @Log(value = "启用题目", type = LogType.ACTIVATE)
    @ValidateDataWith(LimsCoreQuestionActivatableValidator.class)
    public void activate(RestJsonWrapperBean wrapper) {
        limsCoreQuestionService.activate(wrapper);
    }
    
    @Override
    @Log(value = "停用题目", type = LogType.ACTIVATE)
    @ValidateDataWith(LimsCoreQuestionDeactivatableValidator.class)
    public void deactivate(RestJsonWrapperBean wrapper) {
        limsCoreQuestionService.deactivate(wrapper);
    }

    @Override
    @Log(value = "注销",type = LogType.SUSPEND)
    @ValidateDataWith(value = LimsCoreQuestionLastSuspendedValidator.class)
    public void suspend(RestJsonWrapperBean wrapper) {
        getService().suspend(wrapper);
    }
}